package com.yaolifei.flower.core;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

import org.nutz.dao.entity.annotation.ColDefine;
import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.Id;
import org.nutz.dao.entity.annotation.Name;
import org.nutz.dao.entity.annotation.Table;

@Table("t_sys_model")
public class Model {
	@Id
	private int modelId;

	@Column
	@ColDefine(width = 64)
	private String modelName;

	@Name
	@ColDefine(width = 64)
	private String physicalName;

	@Column
	private boolean isGroup = false;

	@Column
	private int parentId;

	@Column
	private int dispOrder;

	@Column
	private boolean created = false;

	private List<ModelColumn> columns;

	public int getModelId() {
		return modelId;
	}

	public void setModelId(int modelId) {
		this.modelId = modelId;
	}

	public String getModelName() {
		return modelName;
	}

	public void setModelName(String modelName) {
		this.modelName = modelName;
	}

	public String getPhysicalName() {
		return physicalName;
	}

	public void setPhysicalName(String physicalName) {
		this.physicalName = physicalName;
	}

	public boolean isGroup() {
		return isGroup;
	}

	public void setGroup(boolean isGroup) {
		this.isGroup = isGroup;
	}

	public int getParentId() {
		return parentId;
	}

	public void setParentId(int parentId) {
		this.parentId = parentId;
	}

	public int getDispOrder() {
		return dispOrder;
	}

	public void setDispOrder(int dispOrder) {
		this.dispOrder = dispOrder;
	}

	public boolean isCreated() {
		return created;
	}

	public void setCreated(boolean created) {
		this.created = created;
	}

	public List<ModelColumn> getColumns() {
		if (columns == null) {
			return Collections.emptyList();
		}
		Collections.sort(columns);
		return columns;
	}

//	public void setColumns(List<ModelColumn> columns) {
//		this.columns = columns;
//	}
	
	public void addColumns(ModelColumn... columns) {
		Collections.addAll(getColumns(), columns);
	}
	
	public void addColumns(Collection<ModelColumn> columns) {
		getColumns().addAll(columns);
	}

	@Override
	public String toString() {
		return modelName;
	}

}
